﻿using KC.ExtensionMethods;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace KC.Tests
{
	[TestClass()]
	public class URITest
	{
		public TestContext TestContext { get; set; }

		[TestMethod()]
		[DeploymentItem("KC.ExtensionMethods.dll")]
		public void GetRootDomainTest()
		{
			Assert.AreEqual("ef.com", new Uri("http://ab.cd.ef.com").GetRootDomain());
			Assert.AreEqual("google.com", new Uri("http://www.google.com").GetRootDomain());
			Assert.AreEqual("google.com", new Uri("http://google.com").GetRootDomain());
			Assert.AreEqual("kconnolly.net", new Uri("http://www.kconnolly.net/Post.aspx?Title=w00terz").GetRootDomain());
		}

		[TestMethod]
		[DeploymentItem("KC.ExtensionMethods.dll")]
		public void GetRootDomainNullTest()
		{
			Uri uri = null;
			Assert.IsNull(uri.GetRootDomain());
		}

		[TestMethod()]
		[DeploymentItem("KC.ExtensionMethods.dll")]
		public void isFromDomainTest()
		{
			Assert.IsTrue(new Uri("http://www.google.com").isFromDomain("google.com"));
			Assert.IsTrue(new Uri("http://google.com").isFromDomain("google.com"));
			Assert.IsFalse(new Uri("http://w00terz.com").isFromDomain("msdn.com"));
		}

		[TestMethod]
		[DeploymentItem("KC.ExtensionMethods.dll")]
		[ExpectedException(typeof(ArgumentNullException), "URI cannot be null!")]
		public void IsFromDomainNullTest()
		{
			new Uri(null).isFromDomain("");
		}

		[TestMethod]
		[DeploymentItem("KC.ExtensionMethods.dll")]
		[ExpectedException(typeof(ArgumentNullException), "Domain cannot be null!")]
		public void IsFromDomainNull2Test()
		{
			new Uri("http://www.google.com").isFromDomain(null);
		}

		[TestMethod]
		[DeploymentItem("KC.ExtensionMethods.dll")]
		[ExpectedException(typeof(ArgumentNullException), "URI cannot be null!")]
		public void IsFromDomainNull3Test()
		{
			Uri uri = null;
			uri.isFromDomain("google.com");
		}

		[TestMethod]
		public void IsMyDomainTest()
		{
			string[] MyDomains = { "http://www.kconnolly.net",
				 "http://www.damnednice.com",
				 "http://www.multimononline.com",
				 "http://www.manymon.com",
				 "http://www.multimon-online.com",
				 "http://www.googlejuicer.com" };
			string[] YourDomains = { "http://www.google.com", "http://www.yahoo.com", "http://www.example.com" };
			
			foreach (string domain in MyDomains)
				Assert.IsTrue(new Uri(domain).isMyDomain(), "Failed on " + domain);
			foreach (string domain in YourDomains)
				Assert.IsFalse(new Uri(domain).isMyDomain(), "Failed to fail on " + domain);
		}
	}
}
